package com.kinghunt.misp.service.impl.userx;

import com.kinghunt.misp.common.param.userx.RoleParam;
import com.kinghunt.misp.dal.dao.userx.RoleDAO;
import com.kinghunt.misp.dal.model.userx.RoleDO;
import com.kinghunt.misp.service.api.userx.RoleWriteService;
import com.bygoodtech.kings.base.utils.ConvertUtil;
import com.bygoodtech.kings.common.dto.ApiResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Description 角色
 * @Author jiangtao
 * @Date 2023/7/5 22:20
 */
@Service
public class RoleWriteServiceImpl implements RoleWriteService {

    @Autowired(required = false)
    RoleDAO roleDAO;

    @Override
    public ApiResult<Long> addRole(RoleParam roleParam) {
        RoleDO record = ConvertUtil.convert(roleParam, RoleDO.class);
        record.setIsDel(Boolean.FALSE);
        int ret = roleDAO.insert(record);
        return ApiResult.ok(record.getId());
    }

    @Override
    public ApiResult<Boolean> updateRoleInfo(RoleParam roleParam) {
        RoleDO record = ConvertUtil.convert(roleParam, RoleDO.class);
        int ret = roleDAO.updateByPrimaryKeySelective(record);
        return ApiResult.ok(true);
    }

    @Override
    public ApiResult<Boolean> deleteRole(Long roleId) {
        RoleDO record = new RoleDO();
        record.setId(roleId);
        record.setIsDel(true);
        int ret = roleDAO.updateByPrimaryKeySelective(record);
        return ApiResult.ok(true);
    }
}
